package com.flu.holidays.constant;

import com.flu.holidays.modeel.DayTypeModel;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 日期类型枚举
 *
 */
@Getter
public enum DayEnum {


    /**
     * 调休
     */
    SHIFT_CHANGE("shiftChange",0, "调休",false),
    /**
     * 节假日，同时为周末及节假日时，归类为节假日
     */
    HOLIDAY("holiday",1, "节假日",true),
    /**
     * 工作日
     */
    WORKING_DAY("workingDay",2, "工作日",false),
    /**
     * 周末
     */
    WEEKEND("weekend",3, "周末",true);

    /**
     * 日期类型描述
     */
    private final String desc;

    /**
     * 日期类型代码
     */
    private final String code;
    /**
     * 日期类型代码
     */
    private final Integer codeInt;
    /**
     * 是否是工作日
     */
    private final Boolean isWorkingDay;

    DayEnum(String code,Integer codeInt, String desc, Boolean isWorkingDay) {
        this.code = code;
        this.codeInt = codeInt;
        this.desc = desc;
        this.isWorkingDay = isWorkingDay;
    }

    public Boolean isWorkingDay() {
        return this.isWorkingDay;
    }


    /**
     * 根据codeInt获取枚举
     *
     * @param codeInt
     * @return
     */
    public static Optional<DayEnum> getByCodeInt(Integer codeInt) {
        return Arrays.stream(DayEnum.values())
                .filter(dayEnum -> dayEnum.codeInt.equals(codeInt))
                .findFirst();
    }

    public DayTypeModel toModel() {
        DayTypeModel result = new DayTypeModel();
        result.setCode(this.codeInt);
        result.setDesc(this.desc);
        result.setType("-");
        return result;
    }

}
